package org.yellow.backend.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yellow.backend.pojo.Appointment;
import org.yellow.backend.service.appointmentService;
import org.yellow.backend.utility.appointmentStatus;

import java.text.ParseException;
import java.util.Date;

/**
 * @author: hy
 * @create: 2024-01-01
 */
@Slf4j
@RestController
@RequestMapping("/appointment")
@CrossOrigin
public class appointmentController {
    @Autowired
    private appointmentService service;
    @GetMapping("/{id}")
    public Appointment getAppointment(@PathVariable("id") int id){
        log.info("查询编号为"+id+"的预约情况");
        return service.selectAppointmentById(id);
    }


    @PostMapping("/insert")
    public Long insertAppointment(@RequestBody Appointment appoint) throws ParseException {
        log.info("插入新的预约情况");
        appoint.setStatus(appointmentStatus.Pending);
        appoint.setAppointmentTime(new Date());
        service.insertAppointment(appoint);
        return appoint.getAppointmentId();
    }


    @GetMapping("getDocId/{id}")
    public Long selectByPatientId(@PathVariable("id") int id){
        return service.selectByPatientId(id);
    }

    @DeleteMapping("/delete/{id}")
    public boolean deleteByPatientId(@PathVariable("id") Long id){
        return service.deleteByPatientId(id);

    }

    @GetMapping("/updateStatus/{id}")
    public boolean updateStatus(@PathVariable("id") int id){
        service.updateStatus(id);

        return true;
    }


}
